package com.manyauthenticationway.server.manyauthenticationway.config

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.cors.CorsConfiguration
import org.springframework.web.cors.UrlBasedCorsConfigurationSource
import org.springframework.web.filter.CorsFilter
/**
 * springboot + security +jwt跨域请求配置*/
@Configuration
class CorsConfig {
    private fun buildConfig(): CorsConfiguration{
        var corsConfiguration = CorsConfiguration();
        corsConfiguration.addAllowedOrigin("*")
        corsConfiguration.addAllowedHeader("*")
        corsConfiguration.addAllowedMethod("*")
        corsConfiguration.allowCredentials
        return corsConfiguration
    }
    @Bean
    fun corsFilter(): CorsFilter {
        var source = UrlBasedCorsConfigurationSource();
        //可以访问的地址
        source.registerCorsConfiguration("/**",buildConfig())
        return CorsFilter(source)
    }
}